package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.entity.Student;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author：汤小洋
 * Date：2024-09-09 15:43
 * Description：<描述>
 */
@RestController
@RequiredArgsConstructor
public class ESController {

    private final ElasticsearchRestTemplate restTemplate;

    /**
     * 创建索引
     */
    @RequestMapping("/createIndex")
    public String create(){
        IndexOperations indexOperations = restTemplate.indexOps(Student.class);
        indexOperations.create();
        return "success";
    }

    /**
     * 创建文档
     */
    @RequestMapping("/createDoc")
    public String createDoc(){
        Student student = new Student(1,"张三",18,"男","西安");
        restTemplate.save(student);
        return "success";
    }


}
